package gui;

import gui.utilitaries.ProductFieldKeyListener;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.SystemColor;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;

public class RecomendationWindow extends JFrame {

	private JPanel contentPane;
	private JTextField textFieldProduct;
	private AutocompleteWindow autocompleteJPanel;
	private String urlProductsIndex;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					//RecomendationWindow frame = new RecomendationWindow();
					//frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public RecomendationWindow(String urlProductsIndex) {
		setBackground(SystemColor.desktop);
		setTitle("Product Opinion Briefing");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 123);
		contentPane = new JPanel();
		contentPane.setLayout(null);
		setContentPane(contentPane);
		
		textFieldProduct = new JTextField();
		textFieldProduct.setBounds(10, 31, 86, 20);
		configureAutoComplete();
		contentPane.add(textFieldProduct);
		textFieldProduct.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("Product");
		lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblNewLabel.setBounds(10, 11, 75, 20);
		contentPane.add(lblNewLabel);
		
		JComboBox comboxProductField = new JComboBox();
		comboxProductField.setModel(new DefaultComboBoxModel(new String[] {"Product ID", "Product Name", "Product Type", "Product Brand"}));
		comboxProductField.setMaximumRowCount(4);
		comboxProductField.setBounds(171, 30, 99, 22);
		contentPane.add(comboxProductField);
		
		JButton btnSearch = new JButton("Search");
		btnSearch.setBounds(309, 30, 91, 23);
		contentPane.add(btnSearch);
		
		//Index opening tasks
		this.urlProductsIndex=urlProductsIndex;
		//End
	}
	public void openAutoCompleteFrame(String baseString){
		this.autocompleteJPanel=new AutocompleteWindow(this.urlProductsIndex);
		this.autocompleteJPanel.setVisible(true);
	}
	/**
	 * This method configures the product textField in order to identify the Ctrl+space+enter combination as a auto-complete calling.
	 */
	public void configureAutoComplete(){
		this.textFieldProduct.addKeyListener(new ProductFieldKeyListener(this));
	}

	public JTextField getTextFieldProduct() {
		return textFieldProduct;
	}

	public void setTextFieldProduct(JTextField textFieldProduct) {
		this.textFieldProduct = textFieldProduct;
	}
	
}
